############# ########### ####### ##### ### ##
#
# Copyright (C) 2010 The Hursk Group, LLC
#
# This program is free software: you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (See file named COPYING).  If not, see 
# <http://www.gnu.org/licenses/>.
# 
############# ########### ####### ##### ### ##

#!/bin/bash
#
#
# full relative to this script path to dir containing system data to be assessed
base_url=/change/me/to/file/location
# path to errata html files
errata_store_dir=redhat_9/


for host_name in `ls $base_url`
do
	for pkg in `cat $base_url$host_name/rpm.qa.out`
	do
		for errata_file in `ls $errata_store_dir`
		do
			hit=`grep $pkg $errata_store_dir$errata_file`
			if [ "$hit" ]; then
				out_date_hit=`grep -C 2 $pkg $errata_store_dir$errata_file | grep "File outdated by"`
				if [ "$out_date_hit" ]; then
					out_date_pkg=`echo $out_date_hit | cut -f4 -d"\"" | cut -f3 -d"/" | cut -f1 -d"."`
					rhsa_md5=`echo $out_date_pkg | md5`
					echo $host_name,$pkg,$out_date_pkg,$rhsa_md5 | cut -f1 -d" "
				fi
			fi	
		done
	done
done
